package sctu.edu.java.year2016.team01.chenhong.day20160521.chapter4_3;

/**
 * Created by Administrator on 2016/5/22.
 * 计算1+1/2!+1/3!+...+1/20!的和
 */
public class Superposition {
    public static void main(String[] args) {

        int i = 1;
        float sum = 0.0f;
        float f;


        while (i < 21) {
            f =factorial(i);
            sum +=1/ f;
            i++;
        }
        System.out.println("1+1/2!+1/3!+...+1/20!的和为：" + sum);

    }




    public static int factorial(int i) {//阶乘
        int j = 1;
        int m = 1;

        while (m <= i ) {
            j *=m;
            m++;
        }
        return j;
    }


}
